//
//  ChoseAreaViewController.m
//  test
//
//  Created by 刘杨 on 14-10-6.
//  Copyright (c) 2014年 刘杨. All rights reserved.
//

#import "ChoseAreaViewController.h"
#import "ChoseParkViewController.h"
#import "AppDelegate.h"



@interface ChoseAreaViewController ()

@end

@implementation ChoseAreaViewController


@synthesize listData ;
@synthesize listImage ;
- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"Hello World");
    NSArray *array = [[NSArray alloc] initWithObjects:@"黄浦区",@"徐汇区",
                      @"静安区",@"闵行区",@"浦东新区", nil];
    NSArray *images = [[NSArray alloc] initWithObjects:@"SouthAfrica.png",@"Mexico.png",
                       @"Argentina.png",@"Nigeria.png",@"England.png",@"USA.png",
                       @"Germany.png",@"Australia.png",@"Holland.png",@"Denmark.png",
                       @"Brazil.png",@"NorthKorea.png",@"Spain.png",@"Switzerland.png",nil];
    self.listData = array;
    self.listImage = images;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


//此处是为了设置分段的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.listData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"ChoseAreaView");
    static NSString *SimpleCellIdentifier = @"SimpleCellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleCellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:SimpleCellIdentifier];
        
    }
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [listData objectAtIndex:row];
    UIImage *img = [UIImage imageNamed:[listImage objectAtIndex:row]];
    cell.imageView.image = img;
    UIColor *testColor1= [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    cell.textLabel.textColor = [UIColor orangeColor];
    [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
    return cell;
    
}


- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger row = [indexPath row];
    NSString *rowValue = [listData objectAtIndex:row];
    NSString *message = [[NSString alloc] initWithFormat:@"你选择了%@队。", rowValue];
    
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"行选择"
                                                   message:message
                                                  delegate:self
                                         cancelButtonTitle:@"Ok"
                                         otherButtonTitles:nil];

    [alert show];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"asasasas");
    UIStoryboard *mainStoryboard =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ChoseParkViewController * choseParkCtl = [mainStoryboard instantiateViewControllerWithIdentifier:@"ChoseParkViewController"];
    choseParkCtl.modalPresentationStyle=UIModalPresentationFormSheet;
    choseParkCtl.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
    AppDelegate * delegate = [[UIApplication sharedApplication] delegate];
    if (delegate.navigationController == nil) {
        NSLog(@"navigationController is nil");
        
    }
    NSLog(@"bbbbbbbbb");
    [delegate.navigationController pushViewController:choseParkCtl animated:YES];
}
     
@end

